package com.va1m.demo.controller;


import com.va1m.demo.common.Result;
import com.va1m.demo.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 会员充值的controller
 * @author Admin
 */
@Controller
@RequestMapping("/api/member")
public class MemberController {

    @Autowired
    MemberService memberService;

    /**
     * 前往充值页面
     *
     * @return
     */
    @GetMapping("/index")
    public String returnMembersIndex() {
        return "members";
    }

    /**
     * 充值
     *
     * @return
     */
    @ResponseBody
    @GetMapping("/recharge")
    public Result recharge(@RequestParam(value = "memberId") Integer memberId,
                           @RequestParam(value = "userId") Integer userId) {
        return Result.ok(memberService.recharge(memberId, userId));
    }

    /**
     * 查询充值会员参数 （金额和时间）
     *
     * @return
     */
    @ResponseBody
    @GetMapping("/getMemberList")
    public Result getMemberList() {
        return Result.ok(memberService.getMemberList());
    }



}
